package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.luo.model.Result;
import com.luo.service.GoodService;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能：根据id批量删除商品
 * 作者：Luo。
 * 日期：2024/1/13 17:02
 */

@WebServlet("/deleteSomeGoods")
    public class DeleteSomeGoodById extends HttpServlet {

    GoodService goodService = new GoodService();
    Result result = new Result();

    @Override
    protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        String ids = req.getParameter("ids");
        String[] split = ids.split(",");
        List<String> list = Arrays.asList(split);
        int i = goodService.deleteSomeGoodsById(list);
        result.setCode("" + i);
        result.setMsg("删除成功");
        String jsonString = JSON.toJSONString(result);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
